﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;

namespace QuanLyThuNgan
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();

        }
       // public static System.Data.SqlClient.SqlConnection cn;//ket noi server a.
        protected override void OnClosed(EventArgs e)
        
        {
            base.OnClosed(e);
            //XtraMessageBox.Show("Bạn chắc là thoát chương trình");
            Application.Exit();
        }

        private void barButtonItemClose_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void barButtonItemObject_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmObject", this);
            if (f == null)
            {
                //frmObject frm = new frmObject();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemProducts_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmProducts", this);
            if (f == null)
            {
                //frmProducts frm = new frmProducts();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemSupplier_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmProvider", this);
            if (f == null)
            {
                //frmProvider frm = new frmProvider();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemCustomer_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmCustomer", this);
            if (f == null)
            {
                //frmCustomer frm = new frmCustomer();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemPrice_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmProductGroup", this);
            if (f == null)
            {
                //frmProductGroup frm = new frmProductGroup();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemOrderCustomer_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmPrinterOrder1", this);
            if (f == null)
            {
                //frmPrinterOrder1 frm = new frmPrinterOrder1();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemOrdersSupplier_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmProviderOrder", this);
            if (f == null)
            {
                //frmProviderOrder frm = new frmProviderOrder();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemBackup_ItemClick(object sender, ItemClickEventArgs e)
        {
            //frmBackup frm = new frmBackup();
            //frm.ShowDialog();
        }

        private void barButtonItemRestore_ItemClick(object sender, ItemClickEventArgs e)
        {
            //frmRestore frm = new frmRestore();
            //frm.ShowDialog();
        }

        private void barButtonItemEmployee_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmPrinter", this);
            if (f == null)
            {
                //frmPrinter frm = new frmPrinter();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            m_getConnect();
            //Uit.it_Conn.getConnect(DonVi_Khac.ConnectS5);
            DonVi_Khac.ConnectPhkham_S3=  axEnCrypt1.DeCrypt(Uit.it_Conn.getConnectString("ConnectString2"), Uit.it_Conn.getPasswordString());
            DonVi_Khac.ConnectS5 = axEnCrypt1.DeCrypt(Uit.it_Conn.getConnectString("ConnectStringS5"), Uit.it_Conn.getPasswordString());
           
            frmLogin frm = new frmLogin();
            frm.ShowDialog();
            if (frmLogin.nd.Thoat == true)
                Application.Exit();
            if (frmLogin.nd.TinhTrang == true)
            {
                barStaticItemTenNV.Caption = frmLogin.nd.HoTen;
                barStaticItemQuyen.Caption = frmLogin.nd.TenMaDonVi;
              //  PhanQuyen.LoadFrmMain(ribbon, 79, 9);
              // load phan quyen
            }
            ribbon.Minimized = true;
        }

        private void m_getConnect()
        {
            Uit.it_Conn.getConnectString();
            Uit.it_Conn.ConnectString = axEnCrypt1.DeCrypt(Uit.it_Conn.ConnectString, Uit.it_Conn.getPasswordString());
            Uit.it_Conn.getConnect();
        }
        private void barButtonItemReport_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void barButtonItemBook_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmBook", this);
            if (f == null)
            {
               
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemInventory_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DangKyCa", this);
            if (f == null)
            {
                frm_DangKyCa frm = new frm_DangKyCa();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemInventoryTotal_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frmInventoryTotal", this);
            if (f == null)
            {
                //frmInventoryTotal frm = new frmInventoryTotal();
                //frm.MdiParent = this;
                //frm.WindowState = FormWindowState.Maximized;
                //frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_NhapChiPhiDichVuNgoaiTru", this);
            if (f == null)
            {
                frm_NhapChiPhiDichVuNgoaiTru frm = new frm_NhapChiPhiDichVuNgoaiTru();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_HoanTien", this);
            if (f == null)
            {
                Frm_HoanTien frm = new Frm_HoanTien();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e)
        {
           
        }

        private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DanhSachBenhNhan", this);
            if (f == null)
            {
                frm_NhapChiPhiDichVuNgoaiTru frm = new frm_NhapChiPhiDichVuNgoaiTru();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

         private void MenuCaLamViec_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_CaLamViec", this);
            if (f == null)
            {
                frm_DM_CaLamViec frm = new frm_DM_CaLamViec();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuDichVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_DichVu", this);
            if (f == null)
            {
                frm_DM_DichVu frm = new frm_DM_DichVu();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuGiaDichVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_GiaDichVu", this);
            if (f == null)
            {
                frm_DM_GiaDichVu frm = new frm_DM_GiaDichVu();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuGiaPhauThuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_GiaPhauThuat", this);
            if (f == null)
            {
                frm_DM_GiaPhauThuat frm = new frm_DM_GiaPhauThuat();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuHetCa_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_HetCa", this);
            if (f == null)
            {
                frm_DM_HetCa frm = new frm_DM_HetCa();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuLoaiDichVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_LoaiDichVu", this);
            if (f == null)
            {
                frm_DM_LoaiDichVu frm = new frm_DM_LoaiDichVu();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuLoaiDichVuYte_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_LoaiDichVuYTe", this);
            if (f == null)
            {
                frm_DM_LoaiDichVuYTe frm = new frm_DM_LoaiDichVuYTe();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MemuNhomVSGPB_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_NhomVSGPB", this);
            if (f == null)
            {
                frm_DM_NhomVSGPB frm = new frm_DM_NhomVSGPB();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void MenuNoiGuiDichVu_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_DM_NoiGuiDichVu", this);
            if (f == null)
            {
                Frm_DM_NoiGuiDichVu frm = new Frm_DM_NoiGuiDichVu();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItemOrdersSell_ItemClick(object sender, ItemClickEventArgs e)
        {
       
        }

        private void barButtonItem_BNNoiTru_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_BenhNhanNoiTru", this);
            if (f == null)
            {
                frm_BenhNhanNoiTru frm = new frm_BenhNhanNoiTru();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem_XacNhan_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_BenhNhanNoiTru", this);
            if (f == null)
            {
                 frm_XacNhan  frm = new frm_XacNhan();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_XacNhanHetCa", this);
            if (f == null)
            {
                Frm_XacNhanHetCa frm = new Frm_XacNhanHetCa();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_XacNhanNopTien", this);
            if (f == null)
            {
                Frm_XacNhanNopTien frm = new Frm_XacNhanNopTien();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem10_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_DanhSachNopTien", this);
            if (f == null)
            {
                Frm_DanhSachNopTien frm = new Frm_DanhSachNopTien();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem11_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_DanhSachNopTien", this);
            if (f == null)
            {
                Frm_ThanhToanXV frm = new Frm_ThanhToanXV();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("frm_NhapChiPhiDichVuNoiTru", this);
            if (f == null)
            {
                frm_NhapChiPhiDichVuNoiTru frm = new frm_NhapChiPhiDichVuNoiTru();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem17_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_ThuDtl_Delete", this);
            if (f == null)
            {
                Frm_ThuDtl_Delete frm = new Frm_ThuDtl_Delete();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem14_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_DM_LyDoXoa", this);
            if (f == null)
            {
                Frm_DM_LyDoXoa frm = new Frm_DM_LyDoXoa();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem15_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_DM_LyDoHoan", this);
            if (f == null)
            {
                Frm_DM_LyDoHoan frm = new Frm_DM_LyDoHoan();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }

        private void barButtonItem16_ItemClick(object sender, ItemClickEventArgs e)
        {
            Form f = FormHelpers.CheckChildFormShow("Frm_DM_LyDoKhongThuTien", this);
            if (f == null)
            {
                Frm_DM_LyDoKhongThuTien frm = new Frm_DM_LyDoKhongThuTien();
                frm.MdiParent = this;
                frm.WindowState = FormWindowState.Maximized;
                frm.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }
    }
}